//
//  SmallDecisionsXjdTemplateItemCell.m
//  SmallDecisions
//
//  Created by 李付雄 on 2025/7/26.
//

#import "SmallDecisionsXjdTemplateItemCell.h"

@interface SmallDecisionsXjdTemplateItemCell()

@property (nonatomic, strong) UIView *contianerBgView;

@end

@implementation SmallDecisionsXjdTemplateItemCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        
        [self createSmallDecisionsXjdTemplateItemCellSubviews];
    }
    return self;
}

- (void)createSmallDecisionsXjdTemplateItemCellSubviews {
    [self contianerBgView];
    [self templateIconLabel];
    [self templateTitleLabel];
    [self templateEditBtn];
}

- (UIView *)contianerBgView {
    if(!_contianerBgView) {
        _contianerBgView = [[UIView alloc] init];
        _contianerBgView.backgroundColor = SmallDecisionsSecondBgColor;
        _contianerBgView.layer.cornerRadius = 10;
        _contianerBgView.layer.masksToBounds = YES;
        [self.contentView addSubview:_contianerBgView];
        [_contianerBgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.right.mas_equalTo(-20);
            make.top.mas_equalTo(5);
            make.bottom.mas_equalTo(-5);
        }];
    }
    
    return _contianerBgView;
}

- (UILabel *)templateIconLabel {
    if(!_templateIconLabel) {
        _templateIconLabel = [[UILabel alloc] init];
        _templateIconLabel.textColor = SmallDecisionsThemeFontColor;
        _templateIconLabel.font = SmallDecisionsSetFontSize(18);
        [self.contianerBgView addSubview:_templateIconLabel];
        [_templateIconLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(15);
            make.left.mas_equalTo(20);
            make.bottom.mas_equalTo(-15);
            make.width.height.mas_equalTo(30);
        }];
    }
    return _templateIconLabel;
}

- (UILabel *)templateTitleLabel {
    if(!_templateTitleLabel) {
        _templateTitleLabel = [[UILabel alloc] init];
        _templateTitleLabel.textColor = SmallDecisionsThemeFontColor;
        _templateTitleLabel.font = SmallDecisionsSetFontSize(16);
        [self.contianerBgView addSubview:_templateTitleLabel];
        [_templateTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.templateIconLabel);
            make.left.mas_equalTo(self.templateIconLabel.mas_right).mas_offset(5);
            make.right.mas_equalTo(-60);
        }];
    }
    
    return _templateTitleLabel;
}

- (UIButton *)templateEditBtn {
    if(!_templateEditBtn) {
        _templateEditBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_templateEditBtn setTitle:@"编辑" forState:UIControlStateNormal];
        [_templateEditBtn setTitleColor:SmallDecisionsRedColor forState:UIControlStateNormal];
        [_templateEditBtn setTitleColor:[UIColor clearColor] forState:UIControlStateHighlighted];
        _templateEditBtn.titleLabel.font = SmallDecisionsSetFontSize(14);
        [_templateEditBtn addTarget:self action:@selector(templateEditBtnAction) forControlEvents:UIControlEventTouchUpInside];
        [self.contianerBgView addSubview:_templateEditBtn];
        [_templateEditBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.templateIconLabel);
            make.right.mas_equalTo(-15);
            make.width.height.mas_equalTo(30);
        }];
    }
    
    return _templateEditBtn;
}

- (void)templateEditBtnAction {
    if (self.templateEditFinishAction) {
        self.templateEditFinishAction(self);
    }
}

@end
